<?php 
	//取得当前的键值	
	$key = current(array_keys($_POST));
	function checkSex(){
			$username = $_POST['sex'];

	$preg = "/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/";

	$c = preg_match($preg, $username);

	if(!$c){
		$arr = array(
			'error'=>1,
			'info'=>'邮箱格式错误'
			);
		echo json_encode($arr);
		exit;
	}
		$arr = array(
			'error'=>0,
			'info'=>'邮箱可用'
			);
	echo json_encode($arr);
	exit;
}
	function checknName(){
		$db = include_once './save.php';
		foreach ($db as $v) {
			if ($v['nikename']==$_POST['nikename']) {
				$arr = array(
					'error'=>1,
					'info' => '昵称已经被使用',
					
					);
				echo json_encode($arr);
				exit();
			}
		}
		$arr = array(
			'error'=>0,
			'info'=>'昵称可用'
			);
		echo json_encode($arr);
			exit;
	}

	function checkuName(){
		$preg = "/^[A-z][0-9A-z]{5,}$/";
		$c = preg_match($preg, $_POST['username']);
		if (!$c) {
			$arr = array(
					'error' => 1,
					'info' => '用户名不合法',
				);
				echo json_encode($arr);
				exit();
		}
		$db = include_once './save.php';
		foreach ($db as $v) {
			if ($v['username']==$_POST['username']) {
				$arr = array(
					'error' => 1,
					'info' => '用户名被占用',
					);
				echo json_encode($arr);
				exit();
			}
		}
		$arr = array(
			'error'=>0,
			'info'=>'用户名可用'
			);
	echo json_encode($arr);
	exit;
	}

	function checkPassword(){
		$preg = "/[A-z0-9]{6,}$/";
		$c=preg_match($preg, $_POST['password']);
		if (!$c) {
			$arr = array(
					'error' => 1,
					'info' => '密码不合格',
					);
				echo json_encode($arr);
				exit();
		}
			$arr = array(
					'error' => 0,
					'info' => '',
					);
				echo json_encode($arr);
				exit();
	}



	switch ($key) {
		case 'sex':
			checkSex();
			break;
		case 'nikename':
			checknName();
			break;
		case 'username':
			checkuName();
			break;
		case 'password':
			checkPassword();
			break;
	}



 ?>